#include<bits/stdc++.h>
#define eb emplace_back
#define ep emplace

using namespace std;
using ll = long long;
constexpr int N = 2e5 + 5, M = 1000000;
constexpr ll inf = 1e18;

int n, a[N]; ll f[N][2], s[N];

struct {
    ll t[M + 5], mx;
    void init() {
        for(int i = 1; i <= M; ++ i) t[i] = -inf;
        mx = 0;
    }
    void update(int p, ll v) {
        t[p] = max(t[p], v), mx = max(mx, v);
    }
} T[2];

void solve() {
    cin >> n;
    for(int i = 1; i <= n; ++ i) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i] * (a[i] == a[i - 1]);
    }
    T[0].init();
    T[1].init();
    for(int i = 1; i <= n; ++ i) {
        for(int j = 0; j < 2; ++ j) {
            f[i][j] = s[i] + T[j ^ 1].mx;
            if(i < n) {
                f[i][j] = max(f[i][j], s[i] + a[i + 1] + T[j ^ 1].t[a[i + 1]]);
                T[j].update(a[i], f[i][j] - s[i + 1]);
            }
        }
    }
    cout << max(f[n][0], f[n][1]) << '\n';
}
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin.tie(0)->sync_with_stdio(0);
    int T;
    cin >> T;

    while(T --) {
        solve();
    }     
    return 0;
}